]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Emit NotificationClosed for a notification iff we destroy it
authorMarina Zhurakhinskaya <marinaz@redhat.com>
Thu, 27 Jan 2011 23:26:53 +0000 (18:26 -0500)
committerMarina Zhurakhinskaya <marinaz@redhat.com>
Fri, 28 Jan 2011 18:02:20 +0000 (13:02 -0500)
This fixes emitting NotificationClosed for resident notifications
that are clicked, but are not actually destroyed.

This also ensures that we emit NotificationClosed in all cases when
a notification is destroyed, which can happen when:
- a non-resident notification is clicked
- an action is invoked on a non-resident notification
- an application the notification was associated with is focused
- a transient notification is done showing
- a notification was requested to be closed by the application
- a tray icon the notification was associated with is removed

https://bugzilla.gnome.org/show_bug.cgi?id=638071

js/ui/messageTray.js
js/ui/notificationDaemon.js

index 073b87accb013e16e543bb11725796862677fc94..1146458856260ef1112555b20fdd6993a88a3dbc 100644 (file)
@@ -41,6 +41,17 @@ const State = {
     HIDING:  3
 };
 
+// These reasons are useful when we destroy the notifications received through
+// the notification daemon. We use EXPIRED for transient notifications that the
+// user did not interact with, DISMISSED for all other notifications that were
+// destroyed as a result of a user action, and SOURCE_CLOSED for the notifications
+// that were requested to be destroyed by the associated source.
+const NotificationDestroyedReason = {
+    EXPIRED: 1,
+    DISMISSED: 2,
+    SOURCE_CLOSED 3
+};
+
 // Message tray has its custom Urgency enumeration. LOW, NORMAL and CRITICAL
 // urgency values map to the corresponding values for the notifications received
 // through the notification daemon. HIGH urgency value is used for chats received
@@ -755,8 +766,10 @@ Notification.prototype = {
         }
     },
 
-    destroy: function() {
-        this.emit('destroy');
+    destroy: function(reason) {
+        if (!reason)
+            reason = NotificationDestroyedReason.DISMISSED;
+        this.emit('destroy', reason);
     }
 };
 Signals.addSignalMethods(Notification.prototype);
@@ -1596,7 +1609,7 @@ MessageTray.prototype = {
         let notification = this._notification;
         this._notification = null;
         if (notification.isTransient)
-            notification.destroy();
+            notification.destroy(NotificationDestroyedReason.EXPIRED);
     },
 
     _expandNotification: function(autoExpanding) {
@@ -1746,7 +1759,7 @@ MessageTray.prototype = {
         let summaryNotification = this._summaryNotification;
         this._summaryNotification = null;
         if (summaryNotification.isTransient && !this._reNotifyWithSummaryNotificationAfterHide)
-            summaryNotification.destroy();
+            summaryNotification.destroy(NotificationDestroyedReason.EXPIRED);
         if (this._reNotifyWithSummaryNotificationAfterHide) {
             this._onNotify(summaryNotification.source, summaryNotification);
             this._reNotifyWithSummaryNotificationAfterHide = false;
index 63062794eec9ed872f101966b4ecf115b429b1fd..4984d48867643e2c188ea206a0954066895d23a7 100644 (file)
@@ -322,13 +322,22 @@ NotificationDaemon.prototype = {
                                                         { icon: iconActor,
                                                           bannerMarkup: true });
             ndata.notification = notification;
-            notification.connect('clicked', Lang.bind(this,
-                function(n) {
-                    this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
-                }));
             notification.connect('destroy', Lang.bind(this,
-                function(n) {
+                function(n, reason) {
                     delete this._notifications[id];
+                    let notificationClosedReason;
+                    switch (reason) {
+                        case MessageTray.NotificationDestroyedReason.EXPIRED:
+                            notificationClosedReason = NotificationClosedReason.EXPIRED;
+                            break;
+                        case MessageTray.NotificationDestroyedReason.DISMISSED:
+                            notificationClosedReason = NotificationClosedReason.DISMISSED;
+                            break;
+                        case MessageTray.NotificationDestroyedReason.SOURCE_CLOSED:
+                            notificationClosedReason = NotificationClosedReason.APP_CLOSED;
+                            break;
+                    }
+                    this._emitNotificationClosed(id, notificationClosedReason);
                 }));
             notification.connect('action-invoked', Lang.bind(this,
                 function(n, actionId) {
@@ -369,10 +378,9 @@ NotificationDaemon.prototype = {
         let ndata = this._notifications[id];
         if (ndata) {
             if (ndata.notification)
-                ndata.notification.destroy();
+                ndata.notification.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
             delete this._notifications[id];
         }
-        this._emitNotificationClosed(id, NotificationClosedReason.APP_CLOSED);
     },
 
     GetCapabilities: function() {